//
//  readJSONToRecord.m
//  JSONHelper
//
//  Created by David Blishen on 22/01/2011
//

#import "readJSONToRecord.h"

@implementation readJSONToRecord

- (id)performDefaultImplementation {
		
	id jsonObject;
	id asRecord;
	NSString *jsonString;
	AEMCodecs *codecs = [[AEMCodecs alloc] init];
	
	// Get the JSON string passed from AppleScript
	
	jsonString = [self directParameter];
	
	// Try and parse the JSON
	
	jsonObject = [jsonString JSONValue];
		
	if (jsonObject==nil) {

		NSLog(@"Failed to parse the JSON supplied by AppleScript");
		jsonObject=@"";
		
	}
	
	// Use appscript framework to pack the object into something we can use
	
	asRecord =[codecs pack:jsonObject];
	[codecs release];
	
	//Return the result to the applescript

	return asRecord;
	
	
	
}

@end
